{extend name="base"}
{block name="style"}
<!-- 这里允许在引入一些样式头部 -->
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="{:_static()}/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="//at.alicdn.com/t/font_tnyc012u2rlwstt9.css" media="all" />
<link rel="stylesheet" href="{:_static()}/css/user.css" media="all" />
<link rel="stylesheet" href="{:_static()}/css/common.css" media="all" />

{/block}

{block name="main"}
<style type="text/css">
	.ws-main{padding: 15px;}
	a:hover{color: inherit !important;}
</style>

	<div class="childrenBody">
	
	<form class="layui-form">
		<div class="user_left">
			<div class="layui-form-item">
			    <label class="layui-form-label">用户名</label>
			    <div class="layui-input-block">
			    	<input type="text" value="{$user.login_name}" disabled class="layui-input layui-disabled">
			    </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">说明</label>
			    <div class="layui-input-block">
			    	<input type="text" value="{$user.remark}" disabled class="layui-input layui-disabled">
			    </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">昵称</label>
			    <div class="layui-input-block">
			    	<input type="text" name="name" value="{$user.name}" placeholder="用户昵称" lay-verify="required" class="layui-input realName">
			    </div>
			</div>
            <div class="layui-form-item">
                <label class="layui-form-label">消息采集间隔</label>
                <div class="layui-input-block">
                    <input type="text" name="wxmsg_interval" value="{$user.wxmsg_interval}" placeholder="微信消息采集间隔 单位：s" lay-verify="required" class="layui-input realName">
                    <div class="gray">每次采集微信消息时间间隔，单位：s</div>
                </div>
            </div>
			<!-- <div class="layui-form-item" pane="">
			    <label class="layui-form-label">性别</label>
			    <div class="layui-input-block userSex">
			    	<input type="radio" name="sex" value="男" title="男" checked="">
	     			<input type="radio" name="sex" value="女" title="女">
	     			<input type="radio" name="sex" value="保密" title="保密">
			    </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">手机号码</label>
			    <div class="layui-input-block">
			    	<input type="tel" value="" placeholder="请输入手机号码" lay-verify="required|phone" class="layui-input userPhone">
			    </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">出生年月</label>
			    <div class="layui-input-block">
			    	<input type="text" value="" placeholder="请输入出生年月" lay-verify="required|date" onclick="layui.laydate({elem: this,max: laydate.now()})" class="layui-input userBirthday">
			    </div>
			</div>
			<div class="layui-form-item userAddress">
			    <label class="layui-form-label">家庭住址</label>
			    <div class="layui-input-inline">
	                <select name="province" lay-filter="province">
	                    <option value="">请选择省</option>
	                </select>
	            </div>
	            <div class="layui-input-inline">
	                <select name="city" lay-filter="city" disabled>
	                    <option value="">请选择市</option>
	                </select>
	            </div>
	            <div class="layui-input-inline">
	                <select name="area" lay-filter="area" disabled>
	                    <option value="">请选择县/区</option>
	                </select>
	            </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">兴趣爱好</label>
			    <div class="layui-input-block userHobby">
			    	<input type="checkbox" name="like[javascript]" title="Javascript">
				    <input type="checkbox" name="like[html]" title="HTML(5)">
				    <input type="checkbox" name="like[css]" title="CSS(3)">
				    <input type="checkbox" name="like[php]" title="PHP">
				    <input type="checkbox" name="like[.net]" title=".net">
				    <input type="checkbox" name="like[ASP]" title="ASP">
				    <input type="checkbox" name="like[C#]" title="C#">
				    <input type="checkbox" name="like[Angular]" title="Angular">
				    <input type="checkbox" name="like[VUE]" title="VUE">
				    <input type="checkbox" name="like[XML]" title="XML">
			    </div>
			</div> -->
			<!-- <div class="layui-form-item">
			    <label class="layui-form-label">邮箱</label>
			    <div class="layui-input-block">
			    	<input type="text" name="email" value="{$user.email}" placeholder="请输入邮箱" lay-verify="required|email" class="layui-input userEmail">
			    </div>
			</div> -->
			<!-- <div class="layui-form-item">
			    <label class="layui-form-label">自我评价</label>
			    <div class="layui-input-block">
			    	<textarea placeholder="请输入内容" class="layui-textarea myself"></textarea>
			    </div>
			</div> -->
		</div>
		<div class="user_right">
			<!-- <input type="file" name="userFace" class="layui-upload-file" lay-title="掐指一算，我要换一个头像了"> -->
			<!-- <p>描述1111111</p> -->
			<!-- <img src="/uploads{$user.head_img}" class="layui-circle" id="userFace"> -->
            <span class="layui-btn ws-uploads-btn">
                <input type="file" value="" class="ws-uploads" title=" ">
                <i class="layui-icon">&#xe64a;</i>
                掐指一算，我要换一个头像了
                
                <input id="material_img" type="hidden" id="filename" value="11">
            </span>

            <div class="layui-input-block">
                <ul id="material_link" class="ws-images">
                    <!-- 这里是图片 -->
                    <li><img id="head_img" src="/uploads{$user.head_img}"></li>
                </ul>
            </div>
		</div>
		<div class="layui-form-item" style="margin-left: 5%;">
		    <div class="layui-input-block">
		    	<button class="layui-btn" lay-submit="" lay-filter="changeUser">立即提交</button>
		    </div>
		</div>
	</form>
	</div>


<script type="text/javascript" src="{:_static()}/layui/layui.js"></script>
<script type="text/babel" src="{:_static()}/js/common.js"></script>
<script type="text/babel" type="text/javascript">
    // var areaData = address;
    var $form;
    var form;
    var $;
    layui.config({
    	base : "js/"
    }).use(['form','layer','upload','laydate'],function(){
    	form = layui.form();
    	var layer = parent.layer === undefined ? layui.layer : parent.layer;
    		$ = layui.jquery;
    		$form = $('form');
    		laydate = layui.laydate;
            // loadProvince(); //加载省信息

            // laydate = layui.laydate,
            taskName={},
            store={}, // 一个容器
            files=[]; // 文件上传表单
        // 文件上传
        util.uploads(["{:url('hloads')}",""],$,function(data){
            let id=data.id,link=data.link;
            console.log(data)
            files.push(id);
            // $("#filename").val(id);
            $("#head_img").attr('src','/uploads'+data.head_img+'');
            // 清除多余的图片
            $('ul.ws-images li').eq(-1).remove();
        }).then(id=>{
            files.forEach((item,i)=>{
                if(item==id){
                    delete files[i];
                }
            })
            console.log(files);
        })
        // //添加验证规则
        // form.verify({
        //     oldPwd : function(value, item){
        //         if(value != "123456"){
        //             return "密码错误，请重新输入！";
        //         }
        //     },
        //     newPwd : function(value, item){
        //         if(value.length < 6){
        //             return "密码长度不能小于6位";
        //         }
        //     },
        //     confirmPwd : function(value, item){
        //         if(!new RegExp($("#oldPwd").val()).test(value)){
        //             return "两次输入密码不一致，请重新输入！";
        //         }
        //     }
        // })

        // //判断是否修改过用户信息，如果修改过则填充修改后的信息
        // if(window.sessionStorage.getItem('userInfo')){
        //     var userInfo = JSON.parse(window.sessionStorage.getItem('userInfo'));
        //     var citys;
        //     $(".realName").val(userInfo.realName); //用户名
        //     $(".userSex input[value="+userInfo.sex+"]").attr("checked","checked"); //性别
        //     $(".userPhone").val(userInfo.userPhone); //手机号
        //     $(".userBirthday").val(userInfo.userBirthday); //出生年月
        //     $(".userAddress select[name='province']").val(userInfo.province); //省
        //     //填充省份信息，同时调取市级信息列表
        //     var value = userInfo.province;
        //     var d = value.split('_');
        //     var code = d[0];
        //     var count = d[1];
        //     var index = d[2];
        //     if (count > 0) {
        //         loadCity(areaData[index].mallCityList);
        //         citys = areaData[index].mallCityList
        //     } else {
        //         $form.find('select[name=city]').attr("disabled","disabled");
        //     }
        //     $(".userAddress select[name='city']").val(userInfo.city); //市
        //     //填充市级信息，同时调取区县信息列表
        //     var value = userInfo.city;
        //     var d = value.split('_');
        //     var code = d[0];
        //     var count = d[1];
        //     var index = d[2];
        //     if (count > 0) {
        //         loadArea(citys[index].mallAreaList);
        //     } else {
        //         $form.find('select[name=area]').attr("disabled","disabled");
        //     }
        //     $(".userAddress select[name='area']").val(userInfo.area); //区
        //     for(key in userInfo){
        //         if(key.indexOf("like") != -1){
        //             $(".userHobby input[name='"+key+"']").attr("checked","checked");
        //         }
        //     }
        //     $(".userEmail").val(userInfo.userEmail); //用户邮箱
        //     $(".myself").val(userInfo.myself); //自我评价
        //     form.render();
        // }

        // //判断是否修改过头像，如果修改过则显示修改后的头像，否则显示默认头像
        // if(window.sessionStorage.getItem('userFace')){
        // 	$("#userFace").attr("src",window.sessionStorage.getItem('userFace'));
        // }else{
        // 	$("#userFace").attr("src","../../images/face.jpg");
        // }

        //提交个人资料
        form.on("submit(changeUser)",function(data){
            console.log(data.field);// 输出所有的表单数据
            //loading层
            var index2 = layer.load(1);
            // ajax提交添加
            $.ajax({
                url:'{:url("member/Usercenter/edituser")}',
                type:'POST',
                data:data.field,
                dataType:'json',
                success:function(data){
                    console.log(data)
                    // 关闭loading
                    layer.close(index2);
                    // 根据返回结果提示操作是否成功
                    if (data.code == 1) {
                        // 修改成功
                        // 关闭输入弹窗
                        // layer.close(index);
                        layer.msg('修改成功');

                        if (data.wait != '') {
                            ttime = data.wait*1000;
                        }
                        else{
                            ttime = 2000;
                        }
                        // 刷新当前页
                        window.setTimeout("window.location.reload()",ttime);
                    }
                    else{
                        // 修改失败
                        layer.msg('修改失败');
                    }
                }
            });
        	return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        })

        // //修改密码
        // form.on("submit(changePwd)",function(data){
        // 	var index = layer.msg('提交中，请稍候',{icon: 16,time:false,shade:0.8});
        //     setTimeout(function(){
        //         layer.close(index);
        //         layer.msg("密码修改成功！");
        //         $(".pwd").val('');
        //     },2000);
        // 	return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        // })

    })

    /*//加载省数据
    function loadProvince() {
        var proHtml = '';
        for (var i = 0; i < areaData.length; i++) {
            proHtml += '<option value="' + areaData[i].provinceCode + '_' + areaData[i].mallCityList.length + '_' + i + '">' + areaData[i].provinceName + '</option>';
        }
        //初始化省数据
        $form.find('select[name=province]').append(proHtml);
        form.render();
        form.on('select(province)', function(data) {
            $form.find('select[name=area]').html('<option value="">请选择县/区</option>');
            var value = data.value;
            var d = value.split('_');
            var code = d[0];
            var count = d[1];
            var index = d[2];
            if (count > 0) {
                loadCity(areaData[index].mallCityList);
            } else {
                $form.find('select[name=city]').attr("disabled","disabled");
            }
        });
    }
    //加载市数据
    function loadCity(citys) {
        var cityHtml = '<option value="">请选择市</option>';
        for (var i = 0; i < citys.length; i++) {
            cityHtml += '<option value="' + citys[i].cityCode + '_' + citys[i].mallAreaList.length + '_' + i + '">' + citys[i].cityName + '</option>';
        }
        $form.find('select[name=city]').html(cityHtml).removeAttr("disabled");
        form.render();
        form.on('select(city)', function(data) {
            var value = data.value;
            var d = value.split('_');
            var code = d[0];
            var count = d[1];
            var index = d[2];
            if (count > 0) {
                loadArea(citys[index].mallAreaList);
            } else {
                $form.find('select[name=area]').attr("disabled","disabled");
            }
        });
    }
    //加载县/区数据
    function loadArea(areas) {
        var areaHtml = '<option value="">请选择县/区</option>';
        for (var i = 0; i < areas.length; i++) {
            areaHtml += '<option value="' + areas[i].areaCode + '">' + areas[i].areaName + '</option>';
        }
        $form.find('select[name=area]').html(areaHtml).removeAttr("disabled");
        form.render();
        form.on('select(area)', function(data) {});
    }*/
</script>
{/block}